﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Media3D;
using System.Windows;
using DataProcessing;
namespace Gene.Render
{
    public class ChromeDataImg
    {
        public const int Width = 1024;
        public const int Height = 768;
        
        public ChromeDataImg()
        {
          
            RenderImage = new RenderTargetBitmap(Width, Height, 96, 96, PixelFormats.Pbgra32);
            
        }
        public RenderTargetBitmap RenderImage
        {
            get;set;
        }
        public int PenLength
        {
            get;
            set;
        }
        public void Draw(int x, int length, Color c)
        {
            
            DrawingVisual drawingVisual = new DrawingVisual();
            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                SolidColorBrush brush = new SolidColorBrush(c);
                drawingContext.DrawLine(new Pen(brush, PenLength), new Point(x, 0), new Point(x, length));

            }

            RenderImage.Render(drawingVisual);
        }
        const double MAX_Y_FOR_DRAW = 0.5;
        public void Draw(uint[] accumulations, Color c)
        {
           
        
            double yMax = ChromePairData.ALL_CurrentAccumulation_Max ;
            RenderImage.Clear();
                 if(accumulations.Length!=ChromePairData.RESOLUTION)
            {
                throw new Exception("error!");
            }
            int i = 0;
            PenLength = Width / ChromePairData.RESOLUTION;
            for (i = 0; i < ChromePairData.RESOLUTION; i++)
            {
                if (accumulations[i] == 0)
                    continue;
                double dAccu = accumulations[i];
        
                double scaleY = dAccu / yMax*MAX_Y_FOR_DRAW;
                
                double y = scaleY * Height;
                if (y ==double.NaN)
                    continue;
                Draw(i * PenLength,(int) y, c);

            }

        }
    }
}
